package com.x.reader.dao;

import com.x.framework.Base;
import com.x.framework.dao.BaseDao;
import com.x.reader.model.History;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class HistoryDao extends BaseDao {

    private final static String selectHistoryListSql = "select t1.* from reader_history t1 where user_id = ? ";

    public List<History> selectHistoryList(History history) throws Exception {
        StringBuilder sb = new StringBuilder(selectHistoryListSql);
        List params = new ArrayList();
        params.add(history.getUserId());
        if (Base.isNotNull(history.getCategoryId())) {
            sb.append("and t1.category_id = ? ");
            params.add(history.getCategoryId());
        }
        sb.append("order by history_create_time desc ");
        return this.queryForList(sb.toString(), History.class, params, history);
    }

}
